package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.ViewRecord;
import com.ruoyi.system.mapper.ViewRecordMapper;
import com.ruoyi.system.service.IViewRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 申请看房记录Service业务层处理
 * 
 * @author ...
 * @date 2022-03-18
 */
@Service
public class ViewRecordServiceImpl implements IViewRecordService 
{
    @Autowired
    private ViewRecordMapper viewRecordMapper;

    /**
     * 查询申请看房记录
     * 
     * @param id 申请看房记录主键
     * @return 申请看房记录
     */
    @Override
    public ViewRecord selectViewRecordById(Integer id)
    {
        return viewRecordMapper.selectViewRecordById(id);
    }

    /**
     * 查询申请看房记录列表
     * 
     * @param viewRecord 申请看房记录
     * @return 申请看房记录
     */
    @Override
    public List<ViewRecord> selectViewRecordList(ViewRecord viewRecord)
    {
        return viewRecordMapper.selectViewRecordList(viewRecord);
    }

    /**
     * 新增申请看房记录
     * 
     * @param viewRecord 申请看房记录
     * @return 结果
     */
    @Override
    public int insertViewRecord(ViewRecord viewRecord)
    {
        viewRecord.setCreateTime(DateUtils.getNowDate());
        return viewRecordMapper.insertViewRecord(viewRecord);
    }

    /**
     * 修改申请看房记录
     * 
     * @param viewRecord 申请看房记录
     * @return 结果
     */
    @Override
    public int updateViewRecord(ViewRecord viewRecord)
    {
        viewRecord.setUpdateTime(DateUtils.getNowDate());
        return viewRecordMapper.updateViewRecord(viewRecord);
    }

    /**
     * 批量删除申请看房记录
     * 
     * @param ids 需要删除的申请看房记录主键
     * @return 结果
     */
    @Override
    public int deleteViewRecordByIds(Integer[] ids)
    {
        return viewRecordMapper.deleteViewRecordByIds(ids);
    }

    /**
     * 删除申请看房记录信息
     * 
     * @param id 申请看房记录主键
     * @return 结果
     */
    @Override
    public int deleteViewRecordById(Integer id)
    {
        return viewRecordMapper.deleteViewRecordById(id);
    }

    @Override
    public List<ViewRecord> getMyRecord() {
        int userId = SecurityUtils.getUserId().intValue();
        return viewRecordMapper.getMyRecord(userId);
    }
}
